﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Animation;
using System.Xml.Linq;

namespace DotNetUI.Models
{
    /// <summary>
    /// 元素动画
    /// </summary>
    public class ElementAnimation
    {
        /// <summary>
        /// 显示控件
        /// </summary>
        /// <typeparam name="TElement"></typeparam>
        /// <param name="element"></param>
        /// <param name="duration"></param>
        public void ShowControl<TElement>(TElement element,TimeSpan duration, double start = 0) where TElement : FrameworkElement
        {
            ShowWidth(element,duration, start);
            ShowHeight(element,duration, start);
        }
        /// <summary>
        /// 显示宽度动画
        /// </summary>
        /// <typeparam name="TElement"></typeparam>
        /// <param name="element"></param>
        /// <param name="duration"></param>
        public void ShowWidth<TElement>(TElement element, TimeSpan duration,double start=0) where TElement : FrameworkElement
        {
            DoubleAnimation widthAnimation = new DoubleAnimation(start, element.Width, new Duration(duration));
            element.BeginAnimation(FrameworkElement.WidthProperty, widthAnimation, HandoffBehavior.Compose);
        }
        /// <summary>
        /// 宽度变窄
        /// </summary>
        /// <typeparam name="TElement"></typeparam>
        /// <param name="element"></param>
        /// <param name="duration"></param>
        /// <param name="end"></param>
        public void HideWidth<TElement>(TElement element, TimeSpan duration, double end=0) where TElement : FrameworkElement
        {
            DoubleAnimation widthAnimation = new DoubleAnimation(element.Width,end, new Duration(duration));
            element.BeginAnimation(FrameworkElement.WidthProperty, widthAnimation, HandoffBehavior.Compose);
        }
        /// <summary>
        /// 高度变低
        /// </summary>
        /// <typeparam name="TElement"></typeparam>
        /// <param name="element"></param>
        /// <param name="duration"></param>
        /// <param name="end"></param>
        public void HideHeight<TElement>(TElement element, TimeSpan duration, double end = 0) where TElement : FrameworkElement
        {
            DoubleAnimation widthAnimation = new DoubleAnimation(element.Height, end, new Duration(duration));
            element.BeginAnimation(FrameworkElement.HeightProperty, widthAnimation, HandoffBehavior.Compose);
        }
        /// <summary>
        /// 显示高度动画
        /// </summary>
        /// <typeparam name="TElement"></typeparam>
        /// <param name="element"></param>
        /// <param name="duration"></param>
        public void ShowHeight<TElement>(TElement element, TimeSpan duration, double start = 0) where TElement : FrameworkElement
        {
            DoubleAnimation widthAnimation = new DoubleAnimation(start, element.Height, new Duration(duration));
            element.BeginAnimation(FrameworkElement.HeightProperty, widthAnimation, HandoffBehavior.Compose);
        }
    }
}
